import GameObject from "./GameObject";
import Utils from "./utils";
import GameConst from "./GameConst";
import SoundsManager from "./soundmanager";

export default class EndBonusIndicator extends GameObject {
    constructor(t, n, r, i, s) {
        super();
        this.delay = -1;
        this.cell = r;
        this.bonusType = s;
        var o = Utils.createBitmap("bonus_new");
        o.pivotX = o.getBounds().width / 2;
        o.pivotY = o.getBounds().height / 2;
        o.x = t;
        o.y = n;
        o.visible = false;
        this.delay = i;
        this.sprite = o;
        Utils.addChild(this.sprite, GameConst.level.hudLayer);
    }

    update(n) {
        super.update(n);
        var r = this;
        this.delay -= n;
        if (this.delay <= 0 && !this.sprite.visible) {
            SoundsManager.instance.playSound("bonus_show");
            this.sprite.visible = true;
            this.sprite.alpha = .3;
            this.sprite.scaleX = this.sprite.scaleY = .3;
            Laya.Tween.to(this.sprite, {
                alpha: 1,
                scaleX: 1,
                scaleY: 1,
                x: this.cell.pos.x,
                y: this.cell.pos.y
            }, EndBonusIndicator.MOVE_TIME * 1e3, Laya.Ease.cubicIn, Laya.Handler.create(this, this.hide));
            GameConst.level.movesLeft = Math.max(0, GameConst.level.movesLeft - 1);
        }
    };
    hide() {
        if (this.cell && this.cell.object) {
            this.cell.object.setBonusType(this.bonusType);
            this.cell.setTempBlock(false, -1);
        }
        this.destroy();
    };
    destroy() {
        super.destroy();
        this.cell = null;
    };
}
Object.defineProperty(EndBonusIndicator.prototype, "totalTime", {
    get: function () {
        return this.delay + EndBonusIndicator.MOVE_TIME;
    },
    enumerable: true,
    configurable: true
});

EndBonusIndicator.MOVE_TIME = .5;